home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Files
/
FileWriter.cp
< prev
next >
Wrap
Text File
|
1997-06-28
|
2KB
|
78 lines
// FileWriter.cp
#ifndef FileWriter_h
#include "FileWriter.h"
#endif
#ifndef ConstBuffer_h
#include "ConstBuffer.h"
#endif
#ifndef FileAccessPath_h
#include "FileAccessPath.h"
#endif
#ifndef DiskFullError_h
#include "DiskFullError.h"
#endif
#ifndef HardwareVolumeLockError_h
#include "HardwareVolumeLockError.h"
#endif
#ifndef SoftwareVolumeLockError_h
#include "SoftwareVolumeLockError.h"
#endif
#ifndef FileLockError_h
#include "FileLockError.h"
#endif
FileWriter::FileWriter( const FileAccessPath& theFile,
uint32 position )
{
Assert( theFile.IsOpen() );
ioParam.ioCompletion = 0;
ioParam.ioRefNum = theFile.RefNum();
ioParam.ioPosMode = fsFromStart;
ioParam.ioPosOffset = position;
}
uint32 FileWriter::operator<<( ConstBuffer& buffer )
{
ioParam.ioBuffer = reinterpret_cast<int8 *>(
const_cast<uint8 *>(
buffer.Unused().Start() ) );
ioParam.ioReqCount = buffer.Unused().Length();
OSErr error = PBWriteSync( this );
buffer.AdvanceMark( ioParam.ioActCount );
ThrowError( error );
return ioParam.ioActCount;
}
void FileWriter::operator<<( ConstData data )
{
ioParam.ioBuffer = reinterpret_cast<int8 *>(
const_cast<uint8 *>(
data.Start() ) );
ioParam.ioReqCount = data.Length();
ThrowError( PBWriteSync( this ) );
Assert( ioParam.ioActCount == data.Length() );
}
void FileWriter::ThrowError( OSErr error )
{
if ( error == noErr )
return;
switch ( error )
{
case dskFulErr: throw DiskFullError( error );
case wPrErr: throw HardwareVolumeLockError( error );
case vLckdErr: throw SoftwareVolumeLockError( error );
case fLckdErr: throw FileLockError( error );
}
throw FileError( error );
}